-- monster_captain
-- created by panyl
-- 冈布奥事件：海怪船长

-- 购买商场物品
EventMgr.register("monster_captain", event.FEED_MONSTER_CAPTAIN, function(para)
    local arr = SlimeEventM.getIdsByRule("monster_captain");
    for index = 1, #arr do
        if SlimeEventM.triggerEvent(arr[index], para) then
            -- 只能触发一个事件，以免多次奖励
            break;
        end
    end
end);

return {
    checkEvent = function(eventId, para)
        local pos = para["pos"];
        local grid = DungeonM.getGridByPos(pos);
        local summon = grid.summon;

        if not summon then
            return false;
        end

        -- 次数
        local dbase = SlimeEventM.query(eventId, "dbase") or {};
        local foodId = dbase["food"];
        local cond = SlimeEventM.query(eventId, "condition");
        if MonsterCaptainM.getFeedTimes(pos, foodId) < cond then
            return false;
        end

        if dbase["slime"] and PetM.getMyPet(dbase["slime"]) then
            -- 奖励冈布奥的，不能已经有冈布奥
            return false;
        end

        if dbase["slime_scrap"] and not PetM.getMyPet(dbase["slime_scrap"]) then
            -- 奖励冈布奥碎片的，需要先有冈布奥
            return false;
        end

        return true;
    end,

    triggerEvent = function(eventId, para)
        local pos = para["pos"];

        -- 把海盗船长干掉
        SummonM.summonDisappear(pos);

        -- 立马保存
        DungeonActionM.immediatelySave();

        EventMgr.fire(event.PLAYER_MOVE, pos);

        return false;
    end,
};

